"""
把csv转到excel的程序
(直接使用xlsxwriter)
"""

import xlsxwriter
from tqdm import tqdm   


def csv_2_excel(csvPath,excelPath,total=None,sep='\t'):
    """
    用openpyxl将csv转化为xlsx
    参数：
        csvPath：csv文件路径
        excelPath：转化成功的excel文件的路径
    """
    wb = xlsxwriter.Workbook(excelPath)
    ws = wb.add_worksheet()

    with open(csvPath,'r',encoding='utf8') as f:
        for nrow,line in tqdm(enumerate(f),total=total):
            row = line.split(sep)
            for ncol,cell in enumerate(row):
                ws.write(nrow,ncol,cell)
        
    
    wb.close()

if __name__ == "__main__":
    csvPath = r"D:\杨博\表\TEfiles\连接器.csv"
    excelPath = r"D:\杨博\表\TEfiles\连接器.xlsx"

    csv_2_excel(csvPath,excelPath,total=266257,sep=',')